package com.dmall.algorithm.chapter03;

import java.util.Arrays;

/**
 * 时间复杂度O(n)
 * 空间复杂度O(n)
 */
public class Leetcode283V1 {

    public void moveZeroes(int[] nums) {
        int[] tempNums = new int[nums.length];
        int count = 0;
        for (int num : nums) {
            if (num != 0) {
                tempNums[count++] = num;
            }
        }
        for (int i = 0; i < tempNums.length; i++) {
            nums[i] = tempNums[i];
        }
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};
        Leetcode283V1 leetcode283 = new Leetcode283V1();
        leetcode283.moveZeroes(nums);
        Arrays.stream(nums).forEach(System.out::println);
    }
}
